home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / pascal2 / pro6 / isdev.pas < prev    next >
Pascal/Delphi Source File  |  1986-08-04  |  1KB  |  37 lines

  1. (* A slight problem with the code listed in message #22 is that
  2. it will diagnose a text file assigned to a DOS device as a disk
  3. file.  To see it for yourself, substitute the name "LPT1" or "COM1"
  4. for the filenames in #22's sample program and watch what results.
  5. The code below will diagnose if the file variable passed is either
  6. thought to be a device by Turbo or DOS. *)
  7.  
  8.  
  9. FUNCTION IsDev(VAR FD) : Boolean;
  10.     {FD should be the address of a file descriptor; IsDev returns
  11.     true if the associated text file is a Turbo or DOS device}
  12.   TYPE
  13.     FIB = RECORD
  14.             handle : Integer;
  15.             flags : Byte;
  16.             rest : ARRAY[3..75] OF Byte;
  17.           END;
  18.     RegPack = RECORD
  19.                 CASE Integer OF
  20.                   1 : (AX, BX, CX, DX, BP, SI, DI, DS, ES, flags : Integer);
  21.                   2 : (AL, AH, BL, BH, CL, CH, DL, DH : Byte);
  22.               END;
  23.   VAR
  24.     f : FIB ABSOLUTE FD;
  25.     registers : RegPack;
  26.   BEGIN
  27.     WITH registers DO
  28.       BEGIN
  29.         AH := $44;            {dos i/o control for devices function}
  30.         AL := 0;              {request device information}
  31.         BX := f.handle;
  32.         MsDos(registers);
  33.         IsDev := ((f.flags AND $F) > 0) OR {turbo thinks it's a device}
  34.         (DL > $7F);                        {dos thinks it's a device}
  35.       END;
  36.   END;
  37.